local hx__fangquan_chen = fk.CreateSkill {
  name = "hx__fangquan_chen",
  tags = {  },
}


hx__fangquan_chen:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__fangquan_chen.name) and data.phase == Player.Start and
    #table.filter(player.room:getAlivePlayers(), function(p) return p:getMark("hx__fangquan_chen_mark") == 0 end) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getAlivePlayers(), function(p) return p:getMark("hx__fangquan_chen_mark") == 0 end)
    local choice = room:askToChoice(player, {
      choices = {"hx__fangquan_chen_draw", "hx__fangquan_chen_skip"},
      skill_name = hx__fangquan_chen.name,
      prompt = "你可以选择一项令一名角色执行（不能选择上个准备阶段选择的角色）",
      cancelable = false,
    })
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      max_num = 1,
      min_num = 1,
      skill_name = hx__fangquan_chen.name,
      prompt = "请选择一名角色执行该效果",
      cancelable = false,
    })
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:getMark("hx__fangquan_chen_mark") ~= 0 then
        room:setPlayerMark(p, "hx__fangquan_chen_mark", 0)
      end
    end
    if choice == "hx__fangquan_chen_draw" then
      room:addPlayerMark(to[1], "hx__fangquan_chen_mark", 1)
      room:addPlayerMark(to[1], "@@hx__fangquan_chen_draw-round", 1)
    elseif choice == "hx__fangquan_chen_skip" then
      room:addPlayerMark(to[1], "hx__fangquan_chen_mark", 1)
      room:addPlayerMark(to[1], "@@hx__fangquan_chen_skip-round", 1)
    end
  end,
})


hx__fangquan_chen:addEffect(fk.EventPhaseChanging, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__fangquan_chen_skip-round") ~= 0 and data.phase == Player.Discard
  end,
  on_use = function(self, event, target, player, data)
    data.skipped = true
  end,
})


hx__fangquan_chen:addEffect(fk.DrawNCards, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__fangquan_chen_draw-round") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 2
  end,
})


return hx__fangquan_chen